package dfferber.xstream;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SuperClassCollection {
	Set<Class<?>> superClasses = new HashSet<Class<?>>();
	Set<Class<?>> acceptedClasses = new HashSet<Class<?>>();
	Set<Class<?>> ignoredClasses = new HashSet<Class<?>>();
	
	public SuperClassCollection() {
		super();
	}

	public void addSuperClass(Class <?> superClass) {
		this.superClasses.add(superClass);
	}
	
	protected boolean contains(Class<?> type) {
		if (ignoredClasses.contains(type)) return false;
		if (acceptedClasses.contains(type)) return true;
		Iterator<Class<?>>	iterator = superClasses.iterator(); 
		while (iterator.hasNext()) {
			Class<?> superClass = iterator.next();
			if (superClass.isAssignableFrom(type)) {
				acceptedClasses.add(type);
				return true;
			}
		}
		ignoredClasses.add(type);
		return false;
	}
}
